package dataflowScheme.diagram.navigator;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.ITreePathLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.ViewerLabel;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
import org.eclipse.ui.navigator.ICommonLabelProvider;

/**
 * @generated
 */
public class ModelNavigatorLabelProvider extends LabelProvider implements
		ICommonLabelProvider, ITreePathLabelProvider {

	/**
	 * @generated
	 */
	static {
		dataflowScheme.diagram.part.ModelDiagramEditorPlugin
				.getInstance()
				.getImageRegistry()
				.put(
						"Navigator?UnknownElement", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
		dataflowScheme.diagram.part.ModelDiagramEditorPlugin
				.getInstance()
				.getImageRegistry()
				.put(
						"Navigator?ImageNotFound", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	public void updateLabel(ViewerLabel label, TreePath elementPath) {
		Object element = elementPath.getLastSegment();
		if (element instanceof dataflowScheme.diagram.navigator.ModelNavigatorItem
				&& !isOwnView(((dataflowScheme.diagram.navigator.ModelNavigatorItem) element)
						.getView())) {
			return;
		}
		label.setText(getText(element));
		label.setImage(getImage(element));
	}

	/**
	 * @generated
	 */
	public Image getImage(Object element) {
		if (element instanceof dataflowScheme.diagram.navigator.ModelNavigatorGroup) {
			dataflowScheme.diagram.navigator.ModelNavigatorGroup group = (dataflowScheme.diagram.navigator.ModelNavigatorGroup) element;
			return dataflowScheme.diagram.part.ModelDiagramEditorPlugin
					.getInstance().getBundledImage(group.getIcon());
		}

		if (element instanceof dataflowScheme.diagram.navigator.ModelNavigatorItem) {
			dataflowScheme.diagram.navigator.ModelNavigatorItem navigatorItem = (dataflowScheme.diagram.navigator.ModelNavigatorItem) element;
			if (!isOwnView(navigatorItem.getView())) {
				return super.getImage(element);
			}
			return getImage(navigatorItem.getView());
		}

		return super.getImage(element);
	}

	/**
	 * @generated
	 */
	public Image getImage(View view) {
		switch (dataflowScheme.diagram.part.ModelVisualIDRegistry
				.getVisualID(view)) {
		case dataflowScheme.diagram.edit.parts.BlockEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Diagram?http://dfs?Block", dataflowScheme.diagram.providers.ModelElementTypes.Block_79); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.StorageEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?http://dfs?Storage", dataflowScheme.diagram.providers.ModelElementTypes.Storage_1001); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.TaskEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?http://dfs?Task", dataflowScheme.diagram.providers.ModelElementTypes.Task_1002); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.TriggerEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?http://dfs?Trigger", dataflowScheme.diagram.providers.ModelElementTypes.Trigger_1003); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.StopperEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?http://dfs?Stopper", dataflowScheme.diagram.providers.ModelElementTypes.Stopper_1004); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.PortSetEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Node?http://dfs?PortSet", dataflowScheme.diagram.providers.ModelElementTypes.PortSet_2001); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.DataPortEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Node?http://dfs?DataPort", dataflowScheme.diagram.providers.ModelElementTypes.DataPort_2002); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.SynchroPortEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Node?http://dfs?SynchroPort", dataflowScheme.diagram.providers.ModelElementTypes.SynchroPort_2003); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.PortSet2EditPart.VISUAL_ID:
			return getImage(
					"Navigator?Node?http://dfs?PortSet", dataflowScheme.diagram.providers.ModelElementTypes.PortSet_2004); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.DataPort2EditPart.VISUAL_ID:
			return getImage(
					"Navigator?Node?http://dfs?DataPort", dataflowScheme.diagram.providers.ModelElementTypes.DataPort_2005); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.SynchroPort2EditPart.VISUAL_ID:
			return getImage(
					"Navigator?Node?http://dfs?SynchroPort", dataflowScheme.diagram.providers.ModelElementTypes.SynchroPort_2006); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.SynchroPort3EditPart.VISUAL_ID:
			return getImage(
					"Navigator?Node?http://dfs?SynchroPort", dataflowScheme.diagram.providers.ModelElementTypes.SynchroPort_2007); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.SynchroPort4EditPart.VISUAL_ID:
			return getImage(
					"Navigator?Node?http://dfs?SynchroPort", dataflowScheme.diagram.providers.ModelElementTypes.SynchroPort_2008); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.SynchroConnectionEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?http://dfs?SynchroConnection", dataflowScheme.diagram.providers.ModelElementTypes.SynchroConnection_3001); //$NON-NLS-1$
		case dataflowScheme.diagram.edit.parts.DataConnectionEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?http://dfs?DataConnection", dataflowScheme.diagram.providers.ModelElementTypes.DataConnection_3002); //$NON-NLS-1$
		}
		return getImage("Navigator?UnknownElement", null); //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private Image getImage(String key, IElementType elementType) {
		ImageRegistry imageRegistry = dataflowScheme.diagram.part.ModelDiagramEditorPlugin
				.getInstance().getImageRegistry();
		Image image = imageRegistry.get(key);
		if (image == null
				&& elementType != null
				&& dataflowScheme.diagram.providers.ModelElementTypes
						.isKnownElementType(elementType)) {
			image = dataflowScheme.diagram.providers.ModelElementTypes
					.getImage(elementType);
			imageRegistry.put(key, image);
		}

		if (image == null) {
			image = imageRegistry.get("Navigator?ImageNotFound"); //$NON-NLS-1$
			imageRegistry.put(key, image);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public String getText(Object element) {
		if (element instanceof dataflowScheme.diagram.navigator.ModelNavigatorGroup) {
			dataflowScheme.diagram.navigator.ModelNavigatorGroup group = (dataflowScheme.diagram.navigator.ModelNavigatorGroup) element;
			return group.getGroupName();
		}

		if (element instanceof dataflowScheme.diagram.navigator.ModelNavigatorItem) {
			dataflowScheme.diagram.navigator.ModelNavigatorItem navigatorItem = (dataflowScheme.diagram.navigator.ModelNavigatorItem) element;
			if (!isOwnView(navigatorItem.getView())) {
				return null;
			}
			return getText(navigatorItem.getView());
		}

		return super.getText(element);
	}

	/**
	 * @generated
	 */
	public String getText(View view) {
		if (view.getElement() != null && view.getElement().eIsProxy()) {
			return getUnresolvedDomainElementProxyText(view);
		}
		switch (dataflowScheme.diagram.part.ModelVisualIDRegistry
				.getVisualID(view)) {
		case dataflowScheme.diagram.edit.parts.BlockEditPart.VISUAL_ID:
			return getBlock_79Text(view);
		case dataflowScheme.diagram.edit.parts.StorageEditPart.VISUAL_ID:
			return getStorage_1001Text(view);
		case dataflowScheme.diagram.edit.parts.TaskEditPart.VISUAL_ID:
			return getTask_1002Text(view);
		case dataflowScheme.diagram.edit.parts.TriggerEditPart.VISUAL_ID:
			return getTrigger_1003Text(view);
		case dataflowScheme.diagram.edit.parts.StopperEditPart.VISUAL_ID:
			return getStopper_1004Text(view);
		case dataflowScheme.diagram.edit.parts.PortSetEditPart.VISUAL_ID:
			return getPortSet_2001Text(view);
		case dataflowScheme.diagram.edit.parts.DataPortEditPart.VISUAL_ID:
			return getDataPort_2002Text(view);
		case dataflowScheme.diagram.edit.parts.SynchroPortEditPart.VISUAL_ID:
			return getSynchroPort_2003Text(view);
		case dataflowScheme.diagram.edit.parts.PortSet2EditPart.VISUAL_ID:
			return getPortSet_2004Text(view);
		case dataflowScheme.diagram.edit.parts.DataPort2EditPart.VISUAL_ID:
			return getDataPort_2005Text(view);
		case dataflowScheme.diagram.edit.parts.SynchroPort2EditPart.VISUAL_ID:
			return getSynchroPort_2006Text(view);
		case dataflowScheme.diagram.edit.parts.SynchroPort3EditPart.VISUAL_ID:
			return getSynchroPort_2007Text(view);
		case dataflowScheme.diagram.edit.parts.SynchroPort4EditPart.VISUAL_ID:
			return getSynchroPort_2008Text(view);
		case dataflowScheme.diagram.edit.parts.SynchroConnectionEditPart.VISUAL_ID:
			return getSynchroConnection_3001Text(view);
		case dataflowScheme.diagram.edit.parts.DataConnectionEditPart.VISUAL_ID:
			return getDataConnection_3002Text(view);
		}
		return getUnknownElementText(view);
	}

	/**
	 * @generated
	 */
	private String getBlock_79Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getStorage_1001Text(View view) {
		IAdaptable hintAdapter = new dataflowScheme.diagram.providers.ModelParserProvider.HintAdapter(
				dataflowScheme.diagram.providers.ModelElementTypes.Storage_1001,
				(view.getElement() != null ? view.getElement() : view),
				dataflowScheme.diagram.part.ModelVisualIDRegistry
						.getType(dataflowScheme.diagram.edit.parts.StorageNameEditPart.VISUAL_ID));
		IParser parser = ParserService.getInstance().getParser(hintAdapter);

		if (parser != null) {
			return parser.getPrintString(hintAdapter, ParserOptions.NONE
					.intValue());
		} else {
			dataflowScheme.diagram.part.ModelDiagramEditorPlugin.getInstance()
					.logError("Parser was not found for label " + 4003); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}

	}

	/**
	 * @generated
	 */
	private String getTask_1002Text(View view) {
		IAdaptable hintAdapter = new dataflowScheme.diagram.providers.ModelParserProvider.HintAdapter(
				dataflowScheme.diagram.providers.ModelElementTypes.Task_1002,
				(view.getElement() != null ? view.getElement() : view),
				dataflowScheme.diagram.part.ModelVisualIDRegistry
						.getType(dataflowScheme.diagram.edit.parts.TaskNameEditPart.VISUAL_ID));
		IParser parser = ParserService.getInstance().getParser(hintAdapter);

		if (parser != null) {
			return parser.getPrintString(hintAdapter, ParserOptions.NONE
					.intValue());
		} else {
			dataflowScheme.diagram.part.ModelDiagramEditorPlugin.getInstance()
					.logError("Parser was not found for label " + 4006); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}

	}

	/**
	 * @generated
	 */
	private String getTrigger_1003Text(View view) {

		IAdaptable hintAdapter = new dataflowScheme.diagram.providers.ModelParserProvider.HintAdapter(
				dataflowScheme.diagram.providers.ModelElementTypes.Trigger_1003,
				(view.getElement() != null ? view.getElement() : view),
				dataflowScheme.diagram.part.ModelVisualIDRegistry
						.getType(dataflowScheme.diagram.edit.parts.WrappingLabelEditPart.VISUAL_ID));
		IParser parser = ParserService.getInstance().getParser(hintAdapter);
		if (parser != null) {
			return parser.getPrintString(hintAdapter, ParserOptions.NONE
					.intValue());
		} else {
			return ""; //$NON-NLS-1$
		}

	}

	/**
	 * @generated
	 */
	private String getStopper_1004Text(View view) {

		IAdaptable hintAdapter = new dataflowScheme.diagram.providers.ModelParserProvider.HintAdapter(
				dataflowScheme.diagram.providers.ModelElementTypes.Stopper_1004,
				(view.getElement() != null ? view.getElement() : view),
				dataflowScheme.diagram.part.ModelVisualIDRegistry
						.getType(dataflowScheme.diagram.edit.parts.WrappingLabel2EditPart.VISUAL_ID));
		IParser parser = ParserService.getInstance().getParser(hintAdapter);
		if (parser != null) {
			return parser.getPrintString(hintAdapter, ParserOptions.NONE
					.intValue());
		} else {
			return ""; //$NON-NLS-1$
		}

	}

	/**
	 * @generated
	 */
	private String getPortSet_2001Text(View view) {
		dataflowScheme.PortSet domainModelElement = (dataflowScheme.PortSet) view
				.getElement();
		if (domainModelElement != null) {
			return String.valueOf(domainModelElement.getType());
		} else {
			dataflowScheme.diagram.part.ModelDiagramEditorPlugin
					.getInstance()
					.logError(
							"No domain element for view with visualID = " + 2001); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getDataPort_2002Text(View view) {
		IAdaptable hintAdapter = new dataflowScheme.diagram.providers.ModelParserProvider.HintAdapter(
				dataflowScheme.diagram.providers.ModelElementTypes.DataPort_2002,
				(view.getElement() != null ? view.getElement() : view),
				dataflowScheme.diagram.part.ModelVisualIDRegistry
						.getType(dataflowScheme.diagram.edit.parts.DataPortNameEditPart.VISUAL_ID));
		IParser parser = ParserService.getInstance().getParser(hintAdapter);

		if (parser != null) {
			return parser.getPrintString(hintAdapter, ParserOptions.NONE
					.intValue());
		} else {
			dataflowScheme.diagram.part.ModelDiagramEditorPlugin.getInstance()
					.logError("Parser was not found for label " + 4001); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}

	}

	/**
	 * @generated
	 */
	private String getSynchroPort_2003Text(View view) {
		IAdaptable hintAdapter = new dataflowScheme.diagram.providers.ModelParserProvider.HintAdapter(
				dataflowScheme.diagram.providers.ModelElementTypes.SynchroPort_2003,
				(view.getElement() != null ? view.getElement() : view),
				dataflowScheme.diagram.part.ModelVisualIDRegistry
						.getType(dataflowScheme.diagram.edit.parts.SynchroPortNameEditPart.VISUAL_ID));
		IParser parser = ParserService.getInstance().getParser(hintAdapter);

		if (parser != null) {
			return parser.getPrintString(hintAdapter, ParserOptions.NONE
					.intValue());
		} else {
			dataflowScheme.diagram.part.ModelDiagramEditorPlugin.getInstance()
					.logError("Parser was not found for label " + 4002); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}

	}

	/**
	 * @generated
	 */
	private String getPortSet_2004Text(View view) {
		dataflowScheme.PortSet domainModelElement = (dataflowScheme.PortSet) view
				.getElement();
		if (domainModelElement != null) {
			return String.valueOf(domainModelElement.getType());
		} else {
			dataflowScheme.diagram.part.ModelDiagramEditorPlugin
					.getInstance()
					.logError(
							"No domain element for view with visualID = " + 2004); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getDataPort_2005Text(View view) {
		IAdaptable hintAdapter = new dataflowScheme.diagram.providers.ModelParserProvider.HintAdapter(
				dataflowScheme.diagram.providers.ModelElementTypes.DataPort_2005,
				(view.getElement() != null ? view.getElement() : view),
				dataflowScheme.diagram.part.ModelVisualIDRegistry
						.getType(dataflowScheme.diagram.edit.parts.DataPortName2EditPart.VISUAL_ID));
		IParser parser = ParserService.getInstance().getParser(hintAdapter);

		if (parser != null) {
			return parser.getPrintString(hintAdapter, ParserOptions.NONE
					.intValue());
		} else {
			dataflowScheme.diagram.part.ModelDiagramEditorPlugin.getInstance()
					.logError("Parser was not found for label " + 4004); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}

	}

	/**
	 * @generated
	 */
	private String getSynchroPort_2006Text(View view) {
		IAdaptable hintAdapter = new dataflowScheme.diagram.providers.ModelParserProvider.HintAdapter(
				dataflowScheme.diagram.providers.ModelElementTypes.SynchroPort_2006,
				(view.getElement() != null ? view.getElement() : view),
				dataflowScheme.diagram.part.ModelVisualIDRegistry
						.getType(dataflowScheme.diagram.edit.parts.SynchroPortName2EditPart.VISUAL_ID));
		IParser parser = ParserService.getInstance().getParser(hintAdapter);

		if (parser != null) {
			return parser.getPrintString(hintAdapter, ParserOptions.NONE
					.intValue());
		} else {
			dataflowScheme.diagram.part.ModelDiagramEditorPlugin.getInstance()
					.logError("Parser was not found for label " + 4005); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}

	}

	/**
	 * @generated
	 */
	private String getSynchroPort_2007Text(View view) {
		IAdaptable hintAdapter = new dataflowScheme.diagram.providers.ModelParserProvider.HintAdapter(
				dataflowScheme.diagram.providers.ModelElementTypes.SynchroPort_2007,
				(view.getElement() != null ? view.getElement() : view),
				dataflowScheme.diagram.part.ModelVisualIDRegistry
						.getType(dataflowScheme.diagram.edit.parts.SynchroPortName3EditPart.VISUAL_ID));
		IParser parser = ParserService.getInstance().getParser(hintAdapter);

		if (parser != null) {
			return parser.getPrintString(hintAdapter, ParserOptions.NONE
					.intValue());
		} else {
			dataflowScheme.diagram.part.ModelDiagramEditorPlugin.getInstance()
					.logError("Parser was not found for label " + 4007); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}

	}

	/**
	 * @generated
	 */
	private String getSynchroPort_2008Text(View view) {
		IAdaptable hintAdapter = new dataflowScheme.diagram.providers.ModelParserProvider.HintAdapter(
				dataflowScheme.diagram.providers.ModelElementTypes.SynchroPort_2008,
				(view.getElement() != null ? view.getElement() : view),
				dataflowScheme.diagram.part.ModelVisualIDRegistry
						.getType(dataflowScheme.diagram.edit.parts.SynchroPortName4EditPart.VISUAL_ID));
		IParser parser = ParserService.getInstance().getParser(hintAdapter);

		if (parser != null) {
			return parser.getPrintString(hintAdapter, ParserOptions.NONE
					.intValue());
		} else {
			dataflowScheme.diagram.part.ModelDiagramEditorPlugin.getInstance()
					.logError("Parser was not found for label " + 4009); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}

	}

	/**
	 * @generated
	 */
	private String getSynchroConnection_3001Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getDataConnection_3002Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getUnknownElementText(View view) {
		return "<UnknownElement Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$ //$NON-NLS-2$
	}

	/**
	 * @generated
	 */
	private String getUnresolvedDomainElementProxyText(View view) {
		return "<Unresolved domain element Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$ //$NON-NLS-2$
	}

	/**
	 * @generated
	 */
	public void init(ICommonContentExtensionSite aConfig) {
	}

	/**
	 * @generated
	 */
	public void restoreState(IMemento aMemento) {
	}

	/**
	 * @generated
	 */
	public void saveState(IMemento aMemento) {
	}

	/**
	 * @generated
	 */
	public String getDescription(Object anElement) {
		return null;
	}

	/**
	 * @generated
	 */
	private boolean isOwnView(View view) {
		return dataflowScheme.diagram.edit.parts.BlockEditPart.MODEL_ID
				.equals(dataflowScheme.diagram.part.ModelVisualIDRegistry
						.getModelID(view));
	}

}
